home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HAM Radio 1997
/
HAM Radio 1997.iso
/
vcls
/
transpar
/
transgrp.pas
next >
Wrap
Pascal/Delphi Source File
|
1996-04-08
|
4KB
|
172 lines
{ THIS IS THE OTHER ONE I WROTE AFTER THE TRANSPARENT RADIO
BUTTON. IT IS A TRANSPARENT GROUP COMPONENT.
Sgt Galen Smallen
EIelson AFBm, AK
}
unit TransGrp;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Menus, StdCtrls;
type
TTransGroup = class(TCustomGroupBox)
private
{ Private declarations }
function GetTransparent: Boolean;
Procedure SetTransparent(Value: Boolean);
protected
{ Protected declarations }
procedure AlignControls(AControl: TControl; var Rect: TRect); override;
procedure paint; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure CreateParams(var Params: TCreateParams); override;
{ just in case someone wants to draw on us }
property Canvas;
published
{ Published declarations }
property Align;
property Caption;
property Ctl3D;
Property Cursor;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property Height default 100;
Property HelpContext;
property Hint;
property left;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Transparentcy: Boolean Read GetTransparent Write SetTransParent default True;
property Visible;
property Width default 100;
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnKeyDown;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('NewTools', [TTransGroup]);
end;
constructor TTransGroup.Create(AOwner: TComponent);
begin
{ call mom }
inherited Create(AOwner);
{ initialize and create some of our properties }
Width := 100; Height := 100;
end;
destructor TTransGroup.Destroy;
begin
{ destroy the properties that we created }
{ nothing in this case }
{ call gozer }
inherited Destroy;
end;
procedure TTransGroup.CreateParams(var Params: TCreateParams);
begin
{ call the create of the params }
inherited CreateParams(Params);
{ and then add our twist, transparency }
if Transparentcy then
Params.ExStyle := Params.ExStyle + WS_EX_Transparent;
end;
procedure TTransGroup.Paint;
var
H: Integer;
R: TRect;
C: array [Byte] of Char;
CLen: Integer;
begin
with Canvas do
begin
Font := Self.Font;
H := TextHeight('0');
R := Rect(0, H, Width, Height);
if Ctl3D then
begin
Inc(R.Left);
Inc(R.Top);
Brush.Color := clBtnHighlight;
FrameRect(R);
OffsetRect(R, -1, -1);
Brush.Color := clBtnShadow;
end else
Brush.Color := clWindowFrame;
FrameRect(R);
StrPCopy(C, Text);
if C[0] <> #0 then
begin
StrPCopy(C, Text);
CLen := StrLen(C);
R := Rect(1, 0, 0, H);
DrawText(Handle, C, CLen, R, DT_LEFT or DT_SINGLELINE or DT_CALCRECT);
if Transparentcy then
begin
SetBkMode(Handle,TRANSPARENT);
SetBkColor(Handle,Color);
end;
SetTextColor(Handle,Font.Color);
DrawText(Handle, C, CLen, R, DT_LEFT or DT_SINGLELINE);
end;
end;
end;
procedure TTransGroup.AlignControls(AControl: TControl; var Rect: TRect);
begin
inherited AlignControls(Acontrol,Rect);
end;
function TTransGroup.GetTransparent: Boolean;
begin
Result := not (csOpaque in ControlStyle);
end;
procedure TTransGroup.SetTransparent(Value: Boolean);
begin
if Transparentcy <> Value then
begin
if Value then
ControlStyle := ControlStyle - [csOpaque] else
ControlStyle := ControlStyle + [csOpaque];
Invalidate;
end;
end;
end.